package com.tedu.mall.controller;

import com.tedu.mall.mapper.AdminMapper;
import com.tedu.mall.pojo.Admin;
import com.tedu.mall.pojo.AdminExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//实现管理员登录
@RestController
@CrossOrigin
public class adminController {
    @Autowired
    AdminMapper adminMapper;
    @RequestMapping("/admin/login")
    //:1314/admin/login?adminName=root&adminPassword=root
    public Admin login(Admin admin){
        AdminExample adminExample=new AdminExample();
        AdminExample.Criteria criteria=adminExample.or();
        criteria.andAdminNameEqualTo(admin.getAdminName());
        criteria.andAdminPasswordEqualTo(admin.getAdminPassword());
        List<Admin> list =adminMapper.selectByExample(adminExample);
        if(list!=null&&list.size()>=1){
            //登录成功 取出管理员的信息
            Admin dbAdmin=list.get(0);
            dbAdmin.setAdminPassword("");
            return dbAdmin;
        }
        return null;
    }
}
